﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OFactoryRenovationEdit : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "OFactoryRenovationList";
            }
        }

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }


        protected int id
        {
            get
            {

                return GetRequestValue<int>("id", 0);
            }
        }
        private OFactoryRenovationInfo _obj = null;
        protected OFactoryRenovationInfo obj
        {
            get
            {
                if (_obj == null)
                {
                    _obj = OFactoryRenovationController.GetList(id);
                }
                return _obj;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "edit")
            {
                addmenu();

            }
        }
        private void addmenu()
        {
            OFactoryRenovationInfo obj2 = Request.SerializableObject<OFactoryRenovationInfo>();
            obj2.CostTotal = obj2.BuyBackCost + obj2.Freight + obj2.CostPart + obj2.CostYY + obj2.CostOther - obj2.CostOldPieces;
            obj2.InTotal = obj2.IsCharges ? (obj2.InPart + obj2.InWork) : 0;

            if (obj2.MachineProperty == "回购车")
            {
                obj2.Loss = obj2.NewContractAmount - obj2.CostTotal;
            }
            else {
                obj2.Loss = obj2.InTotal - obj2.CostTotal;
            }

            bool msg = OFactoryRenovationController.Update(obj2);

            AddLog(Permission.修改, obj2);

            if (msg)
                SuccessJson("修改成功", DWZRef);
            else
            {

                ErrorJson("修改失败");
            }
        }
    }
}